<?php
class TuansController extends AppController {

	var $name = 'Tuans';
	var $helpers = array('Html', 'Form','Ajax');

	function index1() {
		$this->Tuan->recursive = 0;
		$this->set('tuans', $this->paginate());
	}
    
    function index($id = null) {
        $hknk = $this->Tuan->Hknk->find('first', array('conditions'=>array('Hknk.id'=>$id)));	
		$this->Huyen->recursive = 1;
		$this->set('tuans', $this->paginate('Tuan',array('Tuan.hknk_id'=>$id)));
        $submenu = array('Các tuần' => array('link'=>array('controller'=>'tuans', 'action'=>'add',$id), 'children'=>null),
                'Danh sách Học kỳ' => array('link'=>array('controller'=>'hknks', 'action'=>'index'), 'children'=>null));
		$this->set(compact('submenu','hknk','id'));
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Tuan', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('tuan', $this->Tuan->read(null, $id));
	}

	function add($id) {
		if (!empty($this->data)) {
			$this->Tuan->create();
			if ($this->Tuan->save($this->data)) {
				$this->Session->setFlash(__('The Tuan has been saved', true));
				$this->redirect(array('action' => 'index',$id));
			} else {
				$this->Session->setFlash(__('The Tuan could not be saved. Please, try again.', true));
			}
		}
		$submenu = array('Danh sách tuần' => array('link'=>array('controller'=>'tuans', 'action'=>'index',$id), 'children'=>null)
						);
		$this->set(compact('hknk','id','submenu'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Tuan', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Tuan->save($this->data)) {
				$this->Session->setFlash(__('The Tuan has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Tuan could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Tuan->read(null, $id);
		}
		$hknks = $this->Tuan->Hknk->find('list');
		$this->set(compact('hknks'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Tuan', true));
			$this->redirect(array('action' => 'index'));
		}
		if ($this->Tuan->del($id)) {
			$this->Session->setFlash(__('Tuan deleted', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('The Tuan could not be deleted. Please, try again.', true));
		$this->redirect(array('action' => 'index'));
	}
    function tuan($id=null){
        
    }
}
?>